Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
Can Javascript Class methods still be considered "pure", if they call other "pure" class methods?

Consider

class Service {
    methodA(input: string[]): number {
        const resB = this.methodB(input);
        return resB * 2;
    }
    methodB(input: string[]): number {
        return input.length;
    }
}

If MethodB is a pure function, can MethodA also be considered a pure function?

What about the case, when MethodB is a pure function from an injected class?

class Service {
    constructor(helper:Helper){}
    methodA(input: string[]): number {
        const resB = this.helper.methodB(input);
        return resB * 2;
    }
}

In both cases I argued yes in my team, because both cases no side effects takes place and the input>output is deterministic.

On the other side, let alone the the fact, that MethodA was using this. inside its function body was enough for other to say no.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda